import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { isTenantRoleLevel, getCurrentOrganizationId, parseParameters } from 'utils/utils'; // 地区定义角色层级判断

function platformApi() {
  return isTenantRoleLevel() ? "".concat(getCurrentOrganizationId(), "/") : '';
}
/**
 * 查询水平结构的地区
 * @param {number} countryId - 国家id
 * @param {object} query - 查询参数
 * @param {string} query.condition - 地区编码/名称
 * @param {page} query.page - 分页信息
 */


export function regionQueryLine(countryId, query) {
  return request("".concat(CPAAS_PLATFORM, "/v1/").concat(platformApi(), "countries/").concat(countryId, "/regions/list"), {
    method: 'GET',
    query: parseParameters(query)
  });
}
/**
 * 懒加载查询树结构地区
 * @param {number} countryId - 国家id
 * @param {string} regionId - 地区Id
 */

export function regionQueryLazyTree(countryId, regionId) {
  return request("".concat(CPAAS_PLATFORM, "/v1/").concat(platformApi(), "countries/").concat(countryId, "/regions/lazy-tree"), {
    method: 'GET',
    query: {
      regionId: regionId
    }
  });
}
/**
 * 更新地区信息
 * @param {number} countryId - 国家id
 * @param {string} regionId - 地区Id
 * @param {object} body - 地区
 */

export function regionUpdate(countryId, regionId, body) {
  return request("".concat(CPAAS_PLATFORM, "/v1/").concat(platformApi(), "countries/").concat(countryId, "/regions/").concat(regionId), {
    method: 'PUT',
    body: body
  });
}
/**
 * 新增地区信息
 * @param {number} countryId - 国家id
 * @param {object} body - 地区
 */

export function regionCreate(countryId, body) {
  return request("".concat(CPAAS_PLATFORM, "/v1/").concat(platformApi(), "countries/").concat(countryId, "/regions"), {
    method: 'POST',
    body: body
  });
}
/**
 * 启用 地区
 * @param {string} regionId - 地区Id
 * @param {object} body - 地区
 */

export function regionEnable(regionId, body) {
  return request("".concat(CPAAS_PLATFORM, "/v1/").concat(platformApi(), "countries/regions/").concat(regionId), {
    method: 'PUT',
    body: body
  });
}
/**
 * 禁用 地区
 * @param {string} regionId - 地区Id
 * @param {object} body - 地区
 */

export function regionDisable(regionId, body) {
  return request("".concat(CPAAS_PLATFORM, "/v1/").concat(platformApi(), "countries/regions/").concat(regionId), {
    method: 'PUT',
    body: body
  });
}
/**
 * 查询指定地区的详情
 * @param {string} regionId - 地区Id
 */

export function regionQueryDetail(regionId) {
  return request("".concat(CPAAS_PLATFORM, "/v1/").concat(platformApi(), "countries/regions/").concat(regionId), {
    method: 'GET'
  });
}